 //机械按键消抖
 module switch_debouncer(
     input clk,
     input raw_switch,
     output reg debounced_switch
 );

     reg [6:0] counter = 0;
     reg last_switch_state = 0;

     always @(posedge clk) begin
         if (raw_switch == last_switch_state) begin
             counter <= counter + 1;
             if (counter >= 127) begin // 简单地使用5000个时钟周期作为消抖延迟
                 debounced_switch <= raw_switch;
                 counter <= 0;
             end
         end else begin
             counter <= 0;
         end
         last_switch_state <= raw_switch;
     end

 endmodule